﻿using SuperFx;
using SuperLottery.Datas;
using SuperLottery.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuperLottery
{
	/// <summary>
	/// 开奖公告服务实现
	/// </summary>
	public class LotteryDrawService : ILotteryDrawService
	{
		LotteryDrawDbService iLotteryDrawDbService = new LotteryDrawDbService();

		/// <summary>
		/// 获取最新开奖公告
		/// </summary>
		/// <param name="count">单页记录数</param>
		/// <param name="page">结果页码</param>
		/// <returns></returns>
		public List<LotteryDraw> GetLatestLotteryDraws(int count, int page)
		{
			if (count < 1) count = 1;
			if (page < 1) page = 1;

			var dbModels = iLotteryDrawDbService.GetLatestLotteryDraws(count, page);
			return dbModels.Convert2<LotteryDraw>();
		}

		/// <summary>
		/// 获取某个玩法（彩种）的最新开奖公告
		/// </summary>
		/// <param name="issuer">发行者</param>
		/// <param name="game">玩法（彩种）</param>
		/// <param name="count">单页记录数</param>
		/// <param name="page">结果页码</param>
		/// <returns></returns>
		public List<LotteryDraw> GetLotteryDraws(string issuer, string game, int count, int page)
		{
			if (count < 1) count = 1;
			if (page < 1) page = 1;

			var dbModels = iLotteryDrawDbService.GetLotteryDraws(issuer, game, count, page);
			return dbModels.Convert2<LotteryDraw>();
		}

		/// <summary>
		/// 获取某个玩法（彩种）某一期的开奖公告
		/// </summary>
		/// <param name="issuer">发行者</param>
		/// <param name="game">玩法（彩种）</param>
		/// <param name="issueNumber">期号</param>
		/// <returns></returns>
		public LotteryDraw GetLotteryDraw(string issuer, string game, string issueNumber)
		{
			var dbModel = iLotteryDrawDbService.GetLotteryDraw(issuer, game, issueNumber);
			return dbModel.Convert2<LotteryDraw>();
		}

		/// <summary>
		/// 获取某个公告的中奖明细
		/// </summary>
		/// <param name="drawId">公告编号</param>
		/// <returns></returns>
		public List<WinningDetail> GetWinningDetails(long drawId)
		{
			var dbModels = iLotteryDrawDbService.GetWinningDetails(drawId);
			return dbModels.Convert2<WinningDetail>();
		}
	}
}
